home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #15
/
Monster Media Number 15 (Monster Media)(July 1996).ISO
/
prog_c
/
cuj0696.zip
/
DWYER.ZIP
/
COUPON.TST
/
GETGCD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-23
|
962b
|
50 lines
/* ============ */
/* getgcd.c */
/* ============ */
#include <defcodes.h>
#include <math.h>
/* ==================================================================== */
/* GetGCD - finds greatest common divisor by Euclid's algorithn */
/* ==================================================================== */
LDBL
GetGCD(LDBL m, LDBL n)
{
LDBL t;
m = floorl(fabsl(m)), n = floorl(fabsl(n));
if (m < n)
{
t = m; m = n; n = t;
}
while (n > 0)
{
t = fmodl(m, n);
m = n, n = t;
}
return (m);
}
# undef TEST
# ifdef TEST
#define MAIN main
#define GETLDBL GetLDBL
#include <miscdefs.h>
void
MAIN()
{
LDBL u, v;
printf("Testing Euclid's algorithm: "
"Needs two integers per call\n\n");
while (main)
{
GETLDBL("Enter first of the next pair: ", &u);
GETLDBL("Enter the second: ", &v);
printf("GCD = %.Lf\n", GetGCD(u,v));
}
}
# endif